<?php
/**
 * Copyright 2011  SURFfoundation
 * 
 * This file is part of ESCAPE.
 * 
 * ESCAPE is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * ESCAPE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with ESCAPE.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * For more information:
 * http://escapesurf.wordpress.com/
 * http://www.surffoundation.nl/
 * 
 * Contact: d.vierkant@utwente.nl
 * 
 * @license http://www.gnu.org/licenses/gpl.html GNU GPLv3
 */
?>
<?php
	/* @var $repositoryUi escape_repositoryui_RepositoryUi */
	$repositoryUi =& $this->requestAttributes['repositoryUi'];
	/* @var $errorMessages array */
	$errorMessages =& $this->requestAttributes['errorMessages'];

	/* @var $editUser escape_repository_User */
	$editUser =& $this->requestAttributes['editUser'];
	
	$fullname = $this->requestAttributes['fullname'];
	$email = $this->requestAttributes['email'];
	$organization = $this->requestAttributes['organization'];
	$dai = $this->requestAttributes['dai'];
	$password = $this->requestAttributes['password'];
	$systemRoles = $this->requestAttributes['systemRoles'];
		
	$userDataSource = $editUser->getDataSource();
	$userIsProvisioned = false;
	if($userDataSource !== null && $userDataSource !== '')
	{
		$userIsProvisioned = true;
	}
	
	$user = $repositoryUi->getUser();
	
	$templateVariables = array();
	$templateVariables['title'] = 'Edit user details';
	$this->requestAttributes['templateVariables'] =& $templateVariables;
?>
<?php $this->displayHeader(); ?>

<div class="escape_Section">

<div class="escape_Selection">

<div class="escape_SectionTitle">Edit user details</div>

<?php
	if(count($errorMessages) > 0)
	{
?>
<div>
<?php
		foreach($errorMessages as $errorMessage)
		{
?>
<div class="escape_Error"><?php print $errorMessage; ?></div>
<?php
		}
?>
</div>
<br />
<?php
	}
?>

<form method="post" action="<?php print htmlspecialchars($repositoryUi->getActionLinkById('adminEditUser', $editUser->getId()))?>" autocomplete="off">
<input type="hidden" name="verb" value="updateAccount" />

<table class="escape_FormTable">
<tr>
<td>
User ID:
</td>
<td>
<?php print htmlspecialchars($editUser->getId()); ?>
</td>
</tr>
<tr>
<td>
Full name:
</td>
<td>
<input type="text" name="fullname" value="<?php print htmlspecialchars($fullname); ?>" />
</td>
</tr>
<tr>
<td>
Email:
</td>
<td>
<input type="text" name="email" value="<?php print htmlspecialchars($email); ?>" />
</td>
</tr>
<tr>
<td>
Organization:
</td>
<td>
<input type="text" name="organization" value="<?php print htmlspecialchars($organization); ?>" /> <span class="escape_Note">(optional)</span>
</td>
</tr>
<tr>
<td>
DAI <?php $repositoryUi->displayInfoTooltip('Digital Author Identifier'); ?>:
</td>
<td>
<input type="text" name="dai" value="<?php print htmlspecialchars($dai); ?>" /> <span class="escape_Note">(optional)</span>
</td>
</tr>
<?php
	// don't allow password changes for provisioned users
	if(!$userIsProvisioned)
	{
?>
<tr>
<td>
Password:
</td>
<td>
<input type="password" name="password" value="" /> <span class="escape_Note">(leave this field blank to keep the current password)</span>
</td>
</tr>
<?php
	}
?>
<tr>
<td>
System roles:
</td>
<td>
<?php
	$availableSystemRoles = escape_repository_User::getAllSystemRoles(true);
	foreach($availableSystemRoles as $availableSystemRoleUri => $availableSystemRoleLabel)
	{
?>
<div>
<input type="checkbox" name="systemRoles[]" value="<?php print htmlspecialchars($availableSystemRoleUri); ?>" <?php if(in_array($availableSystemRoleUri, $systemRoles))	{ ?>checked="checked"<?php } ?> />
<?php print htmlspecialchars($availableSystemRoleLabel); ?>
</div>
<?php
	}
?>
</td>
</tr>
</table>

<?php
	if($userIsProvisioned)
	{
?>
<p class="escape_Note">
<em>
Warning: this user account was created automatically, the account details might be overwritten next time the user logs on.
<br />
Data source identifier: <?php print htmlspecialchars($userDataSource); ?>
</em>
</p>
<?php
	}
?>

<input type="submit" value="Update" />
<input type="button" value="Delete" onclick="window.location = <?php print htmlspecialchars(json_encode($repositoryUi->getActionLinkById('AdminDeleteUser', $editUser->getId())))?>; return false" />
<input type="button" value="Cancel" onclick="window.location = <?php print htmlspecialchars(json_encode($repositoryUi->getActionLinkById('AdminListUsers')))?>; return false" />

</form>

</div>

</div>

<?php $this->displayFooter(); ?>
